package 力扣._740_删除并获得点数;

public class Solution {

    public int deleteAndEarn(int[] nums) {
        int[] sum = new int[10010];
        int[] dp = new int[10010];

        for (int num : nums) {
            sum[num] += num;
        }
        dp[1] = sum[1];
        for (int i = 2; i < dp.length; i++) {
            int t1 = sum[i], t2 = dp[i - 1];
            if (i - 2 > 0)
                t1 = dp[i - 2] + sum[i];
            dp[i] = Math.max(t1, t2);
        }
        return dp[sum.length - 1];


        //dp[i] = max(dp[i-2] +nums[i], dp[i-1])
    }

    public static void main(String[] args) {
        int i = new Solution().deleteAndEarn(new int[]{4, 10, 10, 8, 1, 4, 10, 9, 7, 6});
        System.out.println(i);
    }
}
